#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
import requests
from base_spider import BaseSpider

class StaplesSpider(BaseSpider):
  def __init__(self, spider):
     super().__init__(spider)

  def getData(self):
    headers = {
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
    }
    req = requests.get(self.url, headers=headers)
    soup = BeautifulSoup(req.text)
    price = soup.find('div', class_='preferred-price-container').find('div', class_='delivery').find('div', class_='delivery-price').string
    title = soup.find('h1', class_="product-title").get_text()
    sku = soup.find(attrs={'itemprop': 'sku'}).string
    return {
      'price': price,
      'title': title,
      'sku': sku,
    }

  def setToDb(self):
    super().setToDb('staples')